﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;

namespace DaveSexton.Labs
{
	[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
		Justification = "It's not a collection, it's a grouping of key/enumerable.")]
	public sealed class LabGroup : IReadOnlyList<Lab>, IList	// IList is required by the Windows Pivot control
	{
		#region Public Properties
		public LabCategory Category
		{
			get
			{
				Contract.Ensures(Contract.Result<LabCategory>() != null);

				return category;
			}
		}

		public int Count
		{
			get
			{
				return labs.Count;
			}
		}

		public bool IsSynchronized
		{
			get
			{
				return false;
			}
		}

		public object SyncRoot
		{
			get
			{
				throw new NotSupportedException();
			}
		}

		public bool IsFixedSize
		{
			get
			{
				return true;
			}
		}

		public bool IsReadOnly
		{
			get
			{
				return true;
			}
		}

		public object this[int index]
		{
			get
			{
				return labs[index];
			}
			set
			{
				throw new NotSupportedException();
			}
		}

		Lab IReadOnlyList<Lab>.this[int index]
		{
			get
			{
				return labs[index];
			}
		}
		#endregion

		#region Private / Protected
		private readonly LabCategory category;
		private readonly IReadOnlyList<Lab> labs;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="LabGroup" /> class.
		/// </summary>
		public LabGroup(LabCategory category, IReadOnlyList<Lab> labs)
		{
			Contract.Requires(category != null);
			Contract.Requires(labs != null);

			this.category = category;
			this.labs = labs;
		}
		#endregion

		#region Methods
		[ContractInvariantMethod]
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")]
		private void ObjectInvariant()
		{
			Contract.Invariant(category != null);
			Contract.Invariant(labs != null);
		}

		public void CopyTo(System.Array array, int index)
		{
			throw new NotSupportedException();
		}

		public int Add(object value)
		{
			throw new NotSupportedException();
		}

		public void Clear()
		{
			throw new NotSupportedException();
		}

		public bool Contains(object value)
		{
			throw new NotSupportedException();
		}

		public int IndexOf(object value)
		{
			throw new NotSupportedException();
		}

		public void Insert(int index, object value)
		{
			throw new NotSupportedException();
		}

		public void Remove(object value)
		{
			throw new NotSupportedException();
		}

		public void RemoveAt(int index)
		{
			throw new NotSupportedException();
		}

		public IEnumerator<Lab> GetEnumerator()
		{
			return labs.GetEnumerator();
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return labs.GetEnumerator();
		}
		#endregion
	}
}